import React from 'react'
import {
    BrowserRouter,
    Route,
    Link,
    NavLink

} from 'react-router-dom'
import '../style/css/bootstrap.min.css'
// import '../style/css/bootstrap-theme.css'
import './console.css'
import NavBar from '../com/NavBar'
import LeftBar from '../com/LeftBar'
import Overview from './overview'
import Users from './users'
import AddUser from './adduser'
import Projects from './projects'
import KeyStore from './keystore'
import AddKey from './addkeystore'
import AddProject from './addproject'
import EditUser from './edituser'
import EditProject from './editproject'
import Me from './me'
class console extends React.Component {
    constructor(props){
        super(props);
        this.state = {user:{uid:-1,name:"",email:"",create_date:""},permission:[]}
    }
    componentDidMount(){
        if(!sessionStorage.user){
            const {history} = this.props;
            history.replace("/login");
        }else{
            this.setState(JSON.parse(sessionStorage.user));
        }
    }
    render() {
        window.console.info(this.state);
        return (
            <div>
                <BrowserRouter basename="/console">
                <div>
                    <NavBar username={this.state.user.name}/>
                    <LeftBar permission={this.state.permission}/>
                        <div className="container-fluid main">
                            <Route exact={true} path="/" component={Overview}/>
                            <Route exact={true} path="/users" component={Users}/>
                            <Route path="/users/add" component={AddUser}/>
                            <Route path="/users/edit" component={EditUser}/>
                            <Route exact={true} path="/projects" component={Projects}/>
                            <Route path="/me" component={Me}/>
                            <Route  path="/projects/add" component={AddProject}/>
                            <Route path="/projects/edit" component={EditProject}/>
                            <Route exact path="/keystore" component={KeyStore}/>
                            <Route path="/keystore/add" component={AddKey}/>
                        </div>
                </div>
                </BrowserRouter>
            </div>


        );
    }
}
export default console;
